package com.xixibaby.message.channel.controller;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.xixibaby.core.Prototypes;
import com.xixibaby.core.message.BaseChannelHandler;
import com.xixibaby.core.message.ChannelHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author tooomj
 */
@Slf4j
@Prototypes(key = ChannelHandler.class, value =  1)
public class ControllerHandler extends BaseChannelHandler<String> {
    @Override
    public boolean handler(String target, String param) {
        String post = HttpUtil.post(target, param);
        JSONObject object = JSONObject.parseObject(post);
        log.info("controller消息返回：[{}]",object );
        return true;
    }

    @Override
    public String convertToParam(Map<String, Object> context) {
        return JSONObject.toJSONString(context);
    }
}
